<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../../plugins/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/rmp.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <blockquote class="layui-elem-quote" style="margin-top: 16px;">
        <span class="layui-badge">说明</span>: 请在此对系统相关的配置进行修改更新，<s>修改完成之后不需要刷新页面便可实时生效，</s><span style="color:red;">更新某些配置需要刷新控制视图页面。</span>
    </blockquote>
    <div class="layui-tab layui-tab-card">
        <ul class="layui-tab-title">
            <li class="layui-this">监控设置</li>
            <li>预警值设置</li>
            <li>保存设置</li>
            <li>其他设置</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form layui-form-pane rmp-setting-form" action="" id="monitoring-setting">
                    <div class="layui-form-item">
                        <label class="layui-form-label">本地缓存数据最大值[条]</label>
                        <div class="layui-input-block">
                            <input type="text" name="maxInfoDataCount" required  lay-verify="required|number" placeholder="根据计算机配置高低斟酌,默认20000条" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">自动清理缓存数据</label>
                        <div class="layui-input-block">
                            <input type="checkbox" id="autoClearDataFlag" lay-skin="switch" lay-text="开启|关闭">
                        </div>
                    </div>
                    <input type="hidden" name="autoClearDataFlag">
                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">清理之前自动保存数据</label>
                        <div class="layui-input-block">
                            <input type="checkbox" id="autoSaveDataFlag" lay-skin="switch" lay-text="开启|关闭">
                        </div>
                    </div>
                    <input type="hidden" name="autoSaveDataFlag">

                    <div class="layui-form-item">
                        <label class="layui-form-label">监控表格刷新频率[ms]</label>
                        <div class="layui-input-block">
                            <input type="text" name="refreshIntervalTime" required  lay-verify="required|number" placeholder="输入大于零的整数" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">预警信息提醒频率[ms]</label>
                        <div class="layui-input-block">
                            <input type="text" name="playNoticIntervalTime" required  lay-verify="required|number" placeholder="输入大于零的整数" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">预警值检测频率[ms]</label>
                        <div class="layui-input-block">
                            <input type="text" name="alertMonitorIntervalTime" required  lay-verify="required|number" placeholder="输入大于零的整数" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">最大数据量检测频率[ms]</label>
                        <div class="layui-input-block">
                            <input type="text" name="cacheDataDetectionIntervalTime" required  lay-verify="required|number" placeholder="输入大于零的整数" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <input type="hidden" value="monitoring" name="type">
                    <div class="layui-form-item">
                        <button class="layui-btn" lay-submit lay-filter="update-setting">更新</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </form>
            </div>
            <div class="layui-tab-item">
            </div>
            <div class="layui-tab-item">
                <form class="layui-form layui-form-pane rmp-setting-form" action="" id="export-setting">
                    <input type="hidden" value="export" name="type">
                    <div class="layui-form-item">
                        <button class="layui-btn" lay-submit lay-filter="update-setting">更新</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </form>
            </div>
            <div class="layui-tab-item">
                <form class="layui-form layui-form-pane rmp-setting-form" action="" id="other-setting">
                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">显示预警信息弹框提示</label>
                        <div class="layui-input-block">
                            <input type="checkbox" id="alertInfoTipShow" lay-skin="switch" lay-text="开启|关闭">
                        </div>
                    </div>
                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">首页地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="home" required  lay-verify="required|url" placeholder="本监控平台的首页地址" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">需求管理平台对接地址1</label>
                        <div class="layui-input-block">
                            <input type="text" name="apiUrl" required  lay-verify="required|url" placeholder="非功能需求数据同步接口地址" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <input type="hidden" name="alertInfoTipShow">
                    <input type="hidden" value="other" name="type">
                    <div class="layui-form-item">
                        <button class="layui-btn" lay-submit lay-filter="update-setting">更新</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="../../plugins/jquery.js"></script>
<script src="../../plugins/layui/layui.js"></script>
<script src="../../js/global.js"></script>
<script>
    layui.use(['element', 'form'], function() {
        var element = layui.element,
                form = layui.form;
        //初始化选项卡高度
        $('.layui-tab-content').height(maxHeight - 160);

        //初始化预警值设置表单
        $('.layui-tab-content > .layui-tab-item:eq(1)').html(templates["setting-alert-value-setting-tpl"]);
       
        //初始化相关值
        $.each(userSetting, function(settingKind, settingInfo){
            //预警设置
            if (settingKind == 'alert') {
                $.each(settingInfo, function(type, setting){
                    $.each(setting, function(key, value){
                        $("#alert-setting").children('div[server-type="' + type + '"]').find('input[name="' + key + '"]').val(value);
                    });
                });
                //监控设置、其他设置、导出设置
            } else {
                $.each(settingInfo, function(key, value){
                    if (typeof value == 'boolean' || (new RegExp("false|true")).test(value)) {
                        $("#" + settingKind + "-setting").find('input[id="' + key + '"]').prop('checked', rmputils.stringUtils.toBoolean(value));
                    }
                    $("#" + settingKind + "-setting").find('input[name="' + key + '"]').val(value);
                });
            }

        });


        form.render('checkbox');

        /********************************************* Form提交监听 ************************************************************************/
        //设置值更新
        form.on('submit(update-setting)', function(data){
            $.post(SETTING_UPDATE_URL, {userKey:userKey, setting:JSON.stringify(data.field)}, function(json) {
                validatReturnJson(json, function(){
                    //更新本地数据
                    var localSetting = userSetting[data.field.type];
                    data.field.type == 'alert' && (localSetting = localSetting[data.field.serverType]);
                    $.each(localSetting, function(key, value){
                        data.field[key] != undefined && (localSetting[key] = data.field[key]);
                    });
                    layer.msg('更新成功!', {icon:1, time:1800});
                });
            });

            return false;
        });


        //监听switch开关,解决switch开关在未被checked时就不返回值的问题
        form.on('switch()', function(data){
            var value = data.elem.checked ? 'true' : 'false';
            $(data.elem).parents('form').find('input[name="' + $(data.elem).attr('id') + '"]').val(value);
        });

        /***************************************************Jquery代理方式批量监听*********************************************************************************/
        $(document).delegates({
            //切换不同类型服务器的预警值设置
            '.layui-elem-field > .layui-field-box > button[server-type]':function(){
                var serverType = $(this).attr('server-type');
                $('#alert-setting > div[server-type="' + serverType + '"]').show('fast').siblings('div[server-type]').hide('fast');
                $(this).removeClass('layui-btn-primary').siblings('button').addClass('layui-btn-primary');
            }
        });


        /****************************************************公用方法********************************************************************************/
        $('.layui-elem-field > .layui-field-box > button[server-type]:eq(0)').click();

    });
</script>
</body>
</html>